<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TestHtml</title>

    <style>
        
        div.tips{
            margin-top: 30px;
        }

        .tips input{
            font-size: 40px;
        }
        
        .tips span{
            color: red;
            font-size: 15px
        }

        input#result{
            margin-top: 30px;
            font-size: 25px;
            width: 100%;
        }
    </style>
</head>
<body>

    <h2>Javascript -> Native</h2>
    <div class="tips">
        <input type="button" value="弹框" onclick="presentAlert()">
        <span>点击Native弹框</span>
    </div>

    <div class="tips">
        <input type="button" value="分享" onclick="share()">
        <span>点击分享，Native响应</span> 
    </div>

    <div class="tips">
        <input type="button" value="支付" onclick="pay()">
        <span>点击支付,Native响应，并传参给Native</span>
    </div>

    
    <div>================================================</div>
    <div> 
    <h2>Native -> Javascript</h2>
        <input id="result" type="text" name="1111" placeholder="显示Native传入的参数"> 
    </div>


<script>

    function presentAlert() {
        alert("I am alert");
    }


    function share() {
        
        //这里可以传任何类型
        var param = {
                        message: "share",
                    };

        window.webkit.messageHandlers.Mobile.postMessage(param);
    }


    function pay() {
        //这里可以传任何类型
        var param = {
                        message: "pay",
                        param:888888
                    };

        window.webkit.messageHandlers.Mobile.postMessage(param);
    }

    function passAnArray(digital){
    
        var text = typeof digital;

        var intro = document.getElementById('result');

        var add = "";
        for (var i = 0; i < digital.length; i++) {
            add += (digital[i] + "、");
        }

        result.value = "参数类型:"+ text + " 参数值:" + add;
    }

</script>

</body>
</html>
